<template>
    <div>
        <div style="text-align:center;margin-bottom:30px;font-size:30px; font-weight:bold;color:rgb(29, 187, 77)">折扣板块内容编辑</div>
        <el-table :data="tableData" stripe :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}" >
            <el-table-column prop="r" label="行" ></el-table-column>
            <el-table-column prop="c1" label="ISBN(列1)"></el-table-column>
            <el-table-column prop="c2" label="ISBN(列2)"></el-table-column>
            <el-table-column prop="c3" label="ISBN(列3)"></el-table-column>
            <el-table-column prop="c4" label="ISBN(列4)"></el-table-column>
            <el-table-column prop="c5" label="ISBN(列5)"></el-table-column>
            <el-table-column prop="c6" label="ISBN(列6)"></el-table-column>
            <el-table-column label="操作" align="center" width="180">
                <template v-slot="scope">
                    <el-button size="mini" type="primary" plain @click="handleEdit(scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-dialog  :visible.sync="formVisible" width="30%">
            <el-form :model="form" label-width="80px" style="padding-right:30px"  ref="formRef">
            <el-form-item label="行" prop="r">
                <el-input v-model="form.r" id="r" disabled></el-input>
            </el-form-item>
            <el-form-item label="列1" prop="c1">
                <el-input v-model="form.c1" id="c1"></el-input>
            </el-form-item>
            <el-form-item label="列2" prop="c2">
                <el-input v-model="form.c2" id="c2"></el-input>
            </el-form-item>
            <el-form-item label="列3" prop="c3">
                <el-input v-model="form.c3" id="c3"></el-input>
            </el-form-item>
            <el-form-item label="列4" prop="c4">
                <el-input v-model="form.c4" id="c4"></el-input>
            </el-form-item>
            <el-form-item label="列5" prop="c5">
                <el-input v-model="form.c5" id="c5"></el-input>
            </el-form-item>
            <el-form-item label="列6" prop="c6">
                <el-input v-model="form.c6" id="c6"></el-input>
            </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="formVisible = false">取 消</el-button>
                <el-button type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>
export default{
    name:"Discount",
    data(){
        return {
            tableData:[],
            formVisible:false,
            form:{},
            user:JSON.parse(localStorage.getItem('honey-user') || '{}'),
        }
    },
    created(){
        this.load()
    },
    methods:{
        handleEdit(row){
            this.form=JSON.parse(JSON.stringify(row))//给form对象赋值,注意要深拷贝
            this.formVisible=true
        },
        save() {   // 保存按钮触发的逻辑  它会触发新增或者更新
            this.$request({
                url: '/exhibition/update',
                method: 'PUT' ,
                data: this.form
            }).then(res => {
                if (res.code === '200') {  // 表示成功保存
                    this.$message.success('保存成功')
                    this.load()
                    this.formVisible = false
                } else {
                    this.$message.error(res.msg)  // 弹出错误的信息
                }
            })
        },

        load() {
        this.$request.get('/exhibition/selectByPlate/折扣专区').then(res => {
            this.tableData = res.data
        })
        },
    }
}
</script>

<style scoped>

</style>